package com.lpinfo.spb.plateform.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lpinfo.spb.framework.base.ResponseData;
import com.lpinfo.spb.plateform.system.dto.SysUserDto;
import com.lpinfo.spb.plateform.system.entity.SysUser;
import com.lpinfo.spb.plateform.system.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户管理")
@Slf4j
@RestController
@RequestMapping("/user")
public class SysUserController {

    @Autowired
    private SysUserService service;


    @ApiOperation("分页列表")
    @GetMapping("/page")
    public ResponseData page(Page page, SysUserDto params){
        IPage<SysUser> result = service.page(page, params);
        return ResponseData.success(result);
    }

    @ApiOperation("保存")
    @PutMapping("/save")
    public ResponseData save(@RequestBody SysUser params){
        boolean result = service.save(params);
        return ResponseData.success(result);
    }

    @ApiOperation("修改根据主键")
    @PutMapping("/updateById")
    public ResponseData updateById(@RequestBody SysUser params){
        boolean result = service.updateById(params);
        return ResponseData.success(result);
    }

    @ApiOperation("查询根据主键")
    @GetMapping("/getById/{userId}")
    public ResponseData getById(@PathVariable("userId") Long userId){
        SysUser result = service.getById(userId);
        return ResponseData.success(result);
    }


}
